Longest Alternating Subsequence
   HOME

TheInfoList



OR:

In
combinatorial Combinatorics is an area of mathematics primarily concerned with counting, both as a means and as an end to obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ...
mathematics,
probability Probability is a branch of mathematics and statistics concerning events and numerical descriptions of how likely they are to occur. The probability of an event is a number between 0 and 1; the larger the probability, the more likely an e ...
, and
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, in the longest alternating subsequence problem, one wants to find a subsequence of a given
sequence In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is cal ...
in which the elements are in alternating order, and in which the sequence is as long as possible. Formally, if \mathbf = \ is a sequence of distinct real numbers, then the subsequence \ is ''alternating'' (or ''zigzag'' or ''down-up'') if :x_ > x_ < x_ > \cdots x_\qquad \text \qquad 1\leq i_1 < i_2 < \cdots < i_k \leq n. Similarly, \mathbf is ''reverse alternating'' (or ''up-down'') if :x_ < x_ > x_ < \cdots x_\qquad \text \qquad 1\leq i_1 < i_2 < \cdots < i_k \leq n. Note that every sequence of length 1 is both alternating and reverse alternating. Let _n(\mathbf) denote the length (number of terms) of the longest alternating subsequence of \mathbf. For example, if we consider some of the permutations of the integers 1,2,3,4,5, we have that * _5(5,4,3,2,1) = 2 , because there are alternating subsequences of length 2, (for example 5,4 or 5,2 or 3,1), but all subsequences of length 3 are not alternating; * _5(1,2,3,4,5) = 1 , because all subsequences of length 2 are not alternating. (actually, they are reverse alternating); * _5(5,1,3,4,2) = 4, because 5,1,3,2 and 5,1,4,2 and 5,3,4,2 are all alternating, and there is no alternating subsequence with more elements; * _5(4,3,5,1,2) = 5, because 4,3,5,1,2 is itself alternating.


Efficient algorithms

In a sequence of distinct elements, the subsequence of
local extrema In mathematical analysis, the maximum and minimum of a function are, respectively, the greatest and least value taken by the function. Known generically as extremum, they may be defined either within a given range (the ''local'' or ''relative' ...
(elements larger than both adjacent elements, or smaller than both adjacent elements) forms a canonical longest alternating sequence. As a consequence, the longest alternating subsequence of a sequence of n elements can be found in time O(n). In sequences that allow repetitions, the same method can be applied after first replacing each run of repeated elements by a single copy of that element.


Distributional results

If \mathbf is a random permutation of the integers 1,2,\ldots,n and A_n \equiv _n(\mathbf), then it is possible to show that : E _n= \frac + \frac \qquad \text \qquad \operatorname _n= \frac - \frac. Moreover, as n \rightarrow \infty, the random variable A_n, appropriately centered and scaled, converges to a standard normal distribution.


Online algorithms

The longest alternating subsequence problem has also been studied in the setting of
online algorithm In computer science, an online algorithm is one that can process its input piece-by-piece in a serial fashion, i.e., in the order that the input is fed to the algorithm, without having the entire input available from the start. In contrast, an of ...
s, in which the elements of \mathbf are presented in an online fashion, and a decision maker needs to decide whether to include or exclude each element at the time it is first presented, without any knowledge of the elements that will be presented in the future, and without the possibility of recalling on preceding observations. Given a sequence X_1, X_2, \ldots, X_n of independent random variables with common continuous distribution F, it is possible to construct a selection procedure that maximizes the expected number of alternating selections. Such expected values can be tightly estimated, and it equals (2-\sqrt)n + O(1). As n \rightarrow \infty, the optimal number of online alternating selections appropriately centered and scaled converges to a normal distribution.


See also

* Alternating permutation *
Permutation pattern In combinatorial mathematics and theoretical computer science, a (classical) permutation pattern is a sub-permutation of a longer permutation. Any permutation may be written in one-line notation as a sequence of entries representing the result of a ...
and pattern avoidance * Counting local maxima and/or local minima in a given sequence * Turning point tests for testing statistical independence of n observations * Number of alternating runs *
Longest increasing subsequence In computer science, the longest increasing subsequence problem aims to find a subsequence of a given sequence in which the subsequence's elements are sorted in an ascending order and in which the subsequence is as long as possible. This subsequenc ...
* Longest common subsequence


References

{{reflist * * * * Problems on strings Permutations Combinatorics Dynamic programming